package com.jinbai.servlet.album;

import com.jinbai.util.DBUtil;
import com.jinbai.util.Log;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

@WebServlet("/studio/album/publish.do")
public class PublishDoServlet extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        final String aid = req.getParameter("aid");
        try (Connection con = DBUtil.connection()) {
            String sql = "update albums set state = 2 where aid = ?";
            try (PreparedStatement ps = con.prepareStatement(sql)) {
                ps.setString(1, aid);
                Log.println("执行SQL：" + ps);
                ps.executeUpdate();
            }
        }
        Log.println("发布成功");
        resp.sendRedirect("/studio/album/list.html");
    }
}
